package com.example.demozmq.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadMain {

    public static void main(String[] args) {
        // 此处只是其中一种线程池，还有很多种线程池，关于线程池的创建不再详述
        ExecutorService pool = Executors.newCachedThreadPool();

        pool.submit(new Runnable() {

            @Override
            public void run() {

                // 此处执行具体的业务逻辑
                for(int i = 1; i <= 100; i++) {
                    System.out.println("线程:" + Thread.currentThread().getName() + "执行了任务" + i + "~~~");
                }
            }
        });

        pool.submit(new Runnable() {

            @Override
            public void run() {

                // 此处执行具体的业务逻辑
                for(int i = 101; i <= 200; i++) {
                    System.out.println("线程:" + Thread.currentThread().getName() + "执行了任务" + i + "~~~");
                }
            }
        });

        pool.submit(new Runnable() {

            @Override
            public void run() {

                // 此处执行具体的业务逻辑
                for(int i = 201; i <= 300; i++) {
                    System.out.println("线程:" + Thread.currentThread().getName() + "执行了任务" + i + "~~~");
                }
            }
        });
    }
}
